package com.junqson.je.content.util;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;


/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/2/5 21:47
 * @Version 1.0
 */
public class PageUtil {

    public static final int DEFAULT_PAGE = 0;
    public static final int DEFAULT_PAGE_SIZE = 20;

    public static Pageable getPageable(Integer page, Integer size) {
        int p = page == null ? DEFAULT_PAGE : page;
        int s = size == null ? DEFAULT_PAGE_SIZE : size;
        return PageRequest.of(p, s);
    }

    public static Pageable getPageable(Integer page, Integer size, Sort sort) {
        int p = page == null ? DEFAULT_PAGE : page;
        int s = size == null ? DEFAULT_PAGE_SIZE : size;
        return PageRequest.of(p, s, sort);
    }

    public static void main(String[] args) {

    }

}
